<%@page import="com.jhs.kjs.dto.UserDTO"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.jhs.kjs.dto.AdminBoardPagingDTO"%>
<%@page import="com.jhs.kjs.dto.UserDTO"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Map"%>
<%@page import="com.jhs.kjs.model.UserModel"%>
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">

<html>
<head>
	
	<%@ include file="/WEB-INF/views/include/common.jsp" %>	
	<title>알당</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="${cssUrl}/base.css" />
<link rel="stylesheet" type="text/css" href="${cssUrl}/contents.css" />
<!-- <script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script> -->
<script language="javascript">
<!--
var firstIndex = 1;
var pushFirst = function(index){
	if(firstIndex == 1){
		firstIndex = index;
	}
}
	function DisplayMenu(index) {
		var menu = undefined;
		var linkIndex = undefined;
		for (var i = ${boardMin }; i <= ${boardMax }; i++){
			try{
				menu = $("#menu"+i);
				linkIndex = $("#linkIndex"+i);
				menu&&menu.css('display','none');
				linkIndex&&linkIndex.removeClass('menu_on');
			}catch(e){}
		}
		
		menu = $("#menu"+index);
		linkIndex = menu.find("#linkIndex"+index);
		menu.css('display','');
		linkIndex.addClass('menu_on');
		
		getBoardList(index);
	}
	-->
</script>

</head>
<body>
<div id="wrap">
	<div class="header">
		<div class="logo">
			<a href="/home"><img src="${imgUrl}/logo.jpg" border="0" /></a>
		</div>
		<div class="top_menu">
			<ul>
				<%
					HttpSession session = request.getSession();
					UserDTO user = (UserDTO)session.getAttribute(UserModel.USER_SESSION_INFO);
					if(session.getAttribute(UserModel.USER_SESSION_INFO)!=null){
						%>
				<li><a href="<c:url value="j_spring_security_logout" />">로그아웃</a></li>
				<%
						if("40".equals(session.getAttribute(UserModel.USER_LEVEL))){
				%>		
				<li><a href="/admin/adminBoardMain">관리자</a></li>
				<%
						} else {
				%>		
				<li><a href="/mypage">마이페이지</a></li>		
				<% } %>
						<%
					}else{
						%>
				<li><a href="/signin">로그인</a></li>
				<li><a href="/user/join1">회원가입</a></li>
				<li><a href="/signin">마이페이지</a></li>		
						<%						
					}
				%>
				
			</ul>
		</div>
		<% if(session.getAttribute(UserModel.USER_SESSION_INFO) !=null){%>
			사용 가능 포인트 : <%=session.getAttribute(UserModel.USER_POINT)%>
		<% } %>
	</div>
	<div class="main_visual">
		<div class="visual">
			<img src="${imgUrl}/main_visual.jpg" border="0" />
		</div>
	</div>
	<div class="main">
		<div class="main_content1">

<%
	Map<String, List<AdminBoardPagingDTO>> boardMap = (Map<String, List<AdminBoardPagingDTO>>)request.getAttribute("boardList");
	Iterator<String> boardIt = boardMap.keySet().iterator();
	String mapKey = "";
	while(boardIt.hasNext()){
		mapKey = boardIt.next();
		List<AdminBoardPagingDTO> boardList = boardMap.get(mapKey);
%>
<script type="text/javascript">
pushFirst(<%=mapKey.replace("boardList","") %>);
</script>
					
		<div class="main_left" id="menu<%=mapKey.replace("boardList","") %>">
				<div class="menu">
					<ul>
<c:forEach var="subMenu" items="${userBoardList }" varStatus="status">

						<li onMouseOver="DisplayMenu(${subMenu.menuIndex })"><a id="linkIndex${subMenu.menuIndex }" href="#" class="">${subMenu.menuName }</a></li>
						<li><img src="${imgUrl}/main_line.jpg" border="0" /></li>
</c:forEach>		
					</ul>
					
				</div>
				<div class="board">
					<div>
						<table border="0" cellspacing="0" cellpadding="0" width="497">
							<tr>
								<td height="1" bgcolor="#7a7c80" colspan="4"></td>
							</tr>
							<tr>
								<td width="61" height="31" bgcolor="#e2e3e3"><font color="#636363"><b>NO.</b></font></td>
								<td width="264" bgcolor="#e2e3e3"><font color="#636363"><b>제목</b></font></td>
								<td width="63" bgcolor="#e2e3e3"><font color="#636363"><b>등록자수</b></font></td>
								<td width="109" bgcolor="#e2e3e3"><font color="#636363"><b>누적금액</b></font></td>
							</tr>
							<tr>
								<td height="1" bgcolor="#cccdcd" colspan="4"></td>
							</tr>
						</table>
						<table border="0" cellspacing="0" cellpadding="0" width="497" id="<%=mapKey %>">
						<%
						for(AdminBoardPagingDTO board : boardList){
							
%>							
							<tr>
								<td width="61" height="31"><%=board.getTextNum() %></td>
								<td width="264" align="left"><a href="#" onClick="goView('<%= board.getBoardType() %>','<%=board.getTextID()%>')"><%=board.getTitle() %></a></td>
								<td width="63"><font color="#3885d7"><b>1명</b></font></td>
								<td width="109"><font color="#cf5050"><b><%=board.getSumPoint() %>원</b></font></td>
							</tr>
							<tr>
								<td height="1" background="${imgUrl}/main_board_line.png" colspan="4"></td>
							</tr>
	<%						
						}
						
						%>
						</table>
						<table border="0" cellspacing="0" cellpadding="0" width="497">
							<tr>
								<td height="10"></td>
							</tr>						
							<tr>
								<td colspan="4" align="center">
								<table border="0" cellspacing="0" cellpadding="0">
									<tr>
										<%-- <td width="22" align="left"><a href="#"><img src="${imgUrl}/main_btn_l2.jpg" border="0" /></a></td>
										<td width="30" align="left"><a href="#"><img src="${imgUrl}/main_btn_l1.jpg" border="0" /></a></td>
										<td class="page"><a href="#" class="page_on">1</a><a href="#">2</a><a href="#">3</a><a href="#">4</a><a href="#">5</a><a href="#">6</a><a href="#">7</a><a href="#">8</a><a href="#">9</a><a href="#">10</a></td>
										<td width="30" align="right"><a href="#"><img src="${imgUrl}/main_btn_r1.jpg" border="0" /></a></td>
										<td width="22" align="right"><a href="#"><img src="${imgUrl}/main_btn_r2.jpg" border="0" /></a></td> --%>
										
										<td width="22" align="left" id="firstLeft<%=mapKey %>"></td>
										<td width="30" align="left" id="left<%=mapKey %>"></td>
										<td class="page" id="cur<%=mapKey %>"></td>
										<td width="30" align="right" id="right<%=mapKey %>"></td>
										<td width="22" align="right" id="endRight<%=mapKey %>"></td>
									</tr>
								</table>
								</td>
							</tr>
							
						</table>
					</div>
				</div>
			</div>						
		
		
		
		<%
		
	}
%>		
			
			
			
			<div class="main_right">
				<div class="right">
				<FORM name="fsearch" style="margin: 0px;" method="post" onkeydown="hitEnterKey(event)" onsubmit="return false;">
					<div class="main_search">
						<div class="input">
							<input type="text" id="ebsSearchName" />
						</div>
						<div class="btn">
							<a href="#" onclick="goSearchEbsList(4)"><img src="${imgUrl}/main_search_btn.jpg" border="0" /></a>
						</div>
					</div>
				</FORM>
					<div class="main_t1">
						<div class="tit">
							<div><img src="${imgUrl}/main_t1.jpg" border="0" /></div>
							<div class="more"><a href="#" onclick="goBoardList(4)">전체보기</a></div>
						</div>
						<div class="content">
							<ul>
								<c:forEach items="${ebsList}" var="ebsList">
									<%-- <li class="left">${fn:substring(ebsList.contents,0, 13)}</li> --%>
									<li class="left"><a href="${ebsList.link}" target="_blank"><c:out value="${fn:substring(ebsList.contents,0, 20)}" escapeXml="false"/></a></li>
								</c:forEach>
							</ul>
						</div>
					</div>
				</div>
				<%-- <div class="main_gallery">
					<div class="btn">
						<div class="left">
							<ul>
								<li><a href="#"><img src="${imgUrl}/main_btn1.jpg" border="0" /></a></li>
								<li><a href="#"><img src="${imgUrl}/main_btn2.jpg" border="0" /></a></li>
							</ul>
						</div>
						<div class="right">
							<ul>
								<li><a href="#"><img src="${imgUrl}/main_btn_on.jpg" border="0" /></a></li>
								<li><a href="#"><img src="${imgUrl}/main_btn_off.jpg" border="0" /></a></li>
								<li><a href="#"><img src="${imgUrl}/main_btn_off.jpg" border="0" /></a></li>
								<li><a href="#"><img src="${imgUrl}/main_btn_off.jpg" border="0" /></a></li>
							</ul>
						</div>
					</div>
					<div class="img">
						<div class="btn1"><a href="#"><img src="${imgUrl}/main_btn_left.png" border="0" /></a></div>
						<div class="img"><a href="#"><img src="${imgUrl}/img.jpg" border="0" width="231" height="121"/></a></div>
						<div class="btn2"><a href="#"><img src="${imgUrl}/main_btn_right.png" border="0" /></a></div>
					</div>
				</div> --%>
			</div>
		</div>
		<div class="main_content2">
			<div class="content1">
				<div class="title">
					<div class="tit"><img src="${imgUrl}/main_t2.jpg" border="0" /></div>
					<div class="more"><a href="#" onClick="goBoardList(1)"><img src="${imgUrl}/main_more.jpg" border="0" /></a></div>
				</div>
				<div class="content">
				<c:forEach items = "${noticeList}" var="board">
					<ul>
						<li class="left"><a href="#" onClick="goView(<c:out value="${board.boardType}" />,'<c:out value="${board.textID}" />')"><c:out value="${board.title}" /></a></li>						
						<li class="right">[<fmt:formatDate value="${board.regiTime }" pattern="yyyy-MM-dd" />]</li>
					</ul>
				</c:forEach>
				</div>
			</div>
			<div class="content1">
				<div class="title">
					<div class="tit"><img src="${imgUrl}/main_t3.jpg" border="0" /></div>
					<div class="more"><a href="#" onClick="goBoardList(2)"><img src="${imgUrl}/main_more.jpg" border="0" /></a></div>
				</div>
				<div class="content">
				<c:forEach items = "${precedentList}" var="precedent">
					<ul>
						<li class="left"><a href="#" onClick="goView(<c:out value="${precedent.boardType}" />,'<c:out value="${precedent.textID}" />')"><c:out value="${precedent.title}" /></a></li>
						<li class="right">[<fmt:formatDate value="${precedent.regiTime }" pattern="yyyy-MM-dd" />]</li>
					</ul>
				</c:forEach>
				</div>
			</div>
			<div class="content2">
				<div class="title">
					<div class="tit"><img src="${imgUrl}/main_t4.jpg" border="0" /></div>
					<div class="more"><a href="#" onClick="goBoardList(3)"><img src="${imgUrl}/main_more.jpg" border="0" /></a></div>
				</div>
				<div class="content">
					<c:forEach items = "${lawList}" var="law">
					<ul>
						<li class="left"><a href="#" onClick="goView(<c:out value="${law.boardType}" />,'<c:out value="${law.textID}" />')"><c:out value="${law.title}" /></a></li>
						<li class="right">[<fmt:formatDate value="${law.regiTime }" pattern="yyyy-MM-dd" />]</li>
					</ul>
				</c:forEach>
				</div>
			</div>
		</div>
	</div>
	<div class="foot">
		<div class="foot_menu">
			<ul>
				<li><a href="javascript:getMsg()">자문 변호사</a></li>
			    <li><img src="${imgUrl}/foot_line.jpg" border="0" /></li>
			    <li><a href="javascript:getMsg()">오픈 매장</a></li>
			    <li><img src="${imgUrl}/foot_line.jpg" border="0" /></li>
			    <li><a href="javascript:getMsg()">할인매장</a></li>
			    <li><img src="${imgUrl}/foot_line.jpg" border="0" /></li>
			    <li><a href="javascript:getMsg()">미아 방지</a></li>
			    <li><img src="${imgUrl}/foot_line.jpg" border="0" /></li>
			    <li><a href="javascript:getMsg()">부동산 및 구인구직</a></li>
			</ul>
		</div>
		<div class="foot_copy">
			<div class="logo"><img src="${imgUrl}/foot_logo.jpg" border="0" /></div>
			<div class="copy"><a href="agree.html">이용약관</a> | <a href="priv.html">개인정보취급방침</a><br />Copyright ⓒ 2014 copyright prtotection center. All RIGHTS RESERVED.</div>
		</div>
	</div>
</div>
<form style="display:none;" name="frm" id="frm" method="post">
	<input type="text" id="menuIndex" name="menuIndex">
	<input type="text" id="textID" name="textID">
</form>
<script type="text/javascript">
	var markerSetting = {
  		paging:{}
  	}
	
	function goView(menuIndex, textID) {		
		if(menuIndex > 4) {
			//로그인 체크
			<% if(session.getAttribute(UserModel.USER_SESSION_INFO) == null) {%> 
				$("#menuIndex").val(menuIndex);
				$("#textID").val(textID);
				$("#frm").attr("action", "/board/userBoardView");
			  	$("#frm").submit();
			  	return;
			<% }%>
			
			var myPoint = 0, boardPoint = 0;
			var isUseCheck = "N";
			
			var url='/board/getMyInfo.json';
			var param = "textID="+textID+"&menuIndex="+menuIndex;
			
			AjaxPost(url, param, function(data){
				myPoint = data.userData.point; //내 금액
				boardPoint = data.boardData.usePoint; //게시글의 구매금액
				isUseCheck = data.usePointCheck; //구매체크
				<% if(!"40".equals(session.getAttribute(UserModel.USER_LEVEL))){ %> 	
				if(myPoint < boardPoint) {
					alert('포인트가 부족합니다.');
					return;			
				}
				
				if(isUseCheck != 'Y') {
					if(!confirm('구매 하시겠습니까?')) {
						return;
					}
				}
				<% } %>
				$("#menuIndex").val(menuIndex);
				$("#textID").val(textID);
				$("#frm").attr("action", "/board/boardView");
			  	$("#frm").submit();
			});	
		} else {
			$("#menuIndex").val(menuIndex);
			$("#textID").val(textID);
			$("#frm").attr("action", "/board/boardView");
		  	$("#frm").submit();
		}
	  	return false;
	}
	
	function goBoardList(menuIndex) {
		$("#menuIndex").val(menuIndex);
		var url = "/board/boardListMain";	
		
		$("#frm").attr("action", url);
		$("#frm").submit();
		
		return false;
	}
	
	function getBoardList(menuIndex) {
		if(markerSetting.paging.menuIndex != menuIndex) {
			markerSetting.paging.nowSeq = 1;
			markerSetting.paging.page = 1;
		}
		markerSetting.paging.menuIndex = menuIndex;
		markerSetting.paging.custom_unit=7;
		var param=markerSetting.paging;
		var list="";
		var url='/board/getBoardList.json';
		$("#boardList"+menuIndex).html("");
		AjaxPost(url, param, function(data){
//	 		jsonLog(data.boardList);
			$.each(data.boardList,function(index, value){
				list += "<tr>";
				list += "	<td width='61' height='31'>"+value.textNum+"</td>";
				list += "	<td width='264'align='left'><a href='#' onclick='goView("+value.boardType+","+value.textID+")', this>"+value.title+"</a></td>";
				list += "	<td width='63' id='regiTime'><font color=''#3885d7'><b>"+value.proCnt+"명</b></font></td>";
				list += "	<td width='109' id='sumPoint'><font color='#cf5050'><b>"+value.sumPoint+"원</b></font></td>";
				list += "   <td width='1' style='display:none;'><input type=hidden id='usePoint' value='"+value.usePoint+"'></td>";					
				list += "</tr>";
				list += "<tr>";
				list += "	<td height='1' background='/resources/images/main_board_line.png' colspan='4'></td>";
				list += "</tr>";				
			});
			$("#boardList"+menuIndex).html(list);
			markerSetting.paging.totalPage= data.totalPage.totalPage;
			//markerSetting.paging.page = data.totalPage.page;
			makePaging(menuIndex);
		});
	}
	
	 	function makePaging(menuIndex) {
				var totalPage = markerSetting.paging.totalPage;
				var nowPage = markerSetting.paging.page;
				var html='';
				var firstLeft="", left="", cur = "", right="", endRight="";
				var setFunctionName='';
				var index=(nowPage-10);
				var indexCount=0;
				
				var endPage = totalPage / 10;
				if (totalPage % 10 > 0) {
					endPage = endPage + 1;
				}
				
				if(index>1){
					firstLeft+='<a onclick="changePaging('+menuIndex+',1,\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/page_btn_12.jpg"/ boarder=0></a>';
					left+='<a onclick="changePaging('+menuIndex+','+index+',\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/page_btn_11.jpg"/  border=0></a>';
				}
//				//logs('totalPage/20 = '+totalPage/20);
				for(;index<=endPage;index++){
					if((index)==nowPage){
						setFunctionName='';
					}else{
						setFunctionName=' onclick="changePaging('+menuIndex+','+index+')"';
					}
					
					if(index>0){
							
						if(index == nowPage) {
							cur+='<a hrer="#" '+setFunctionName+' class=\'sub_page_on\'>'+index+'</a>';
						} else {
							cur+='<a href="#" '+setFunctionName+'>'+index+'</a>';
						}
						
						indexCount++;
					}
					if(indexCount>9){
						right+='<a onclick="changePaging('+menuIndex+','+index+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/page_btn_r1.jpg"/ border=0></a>';
						endRight+='<a onclick="changePaging('+menuIndex+','+totalPage+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/page_btn_r2.jpg"/ border=0></a>';
						break;
					}
					
				}
				
				$("#firstLeftboardList"+menuIndex).html(firstLeft);
				$("#leftboardList"+menuIndex).html(left);
				$("#curboardList"+menuIndex).html(cur);
				$("#rightboardList"+menuIndex).html(right);
				$("#endRightboardList"+menuIndex).html(endRight);
		  }
		  
		  function changePaging(menuIndex, index, option){
			  
				logs('markerSetting.paging.totalPage = '+markerSetting.paging.totalPage);
				if(option==null){
					logs(', index = '+index);
					
					markerSetting.paging.page=index;
					markerSetting.paging.start=0;
					markerSetting.paging.end=0;
					getBoardList(menuIndex);
				}else{
					if(option=='before'){
						var next = index-9;
						while(next<=0){
							next++;
						}
						logs('next = '+next+', index = '+index);
						markerSetting.paging.page=next;
						markerSetting.paging.start=0;
						markerSetting.paging.end=0;
						getBoardList(menuIndex);
					}else if(option=='after'){
						var next = index+9;
						while(next>=(markerSetting.paging.totalPage/10)+1){
							next--;
						}
						logs('next = '+next+', index = '+index);
						markerSetting.paging.page=next;
						markerSetting.paging.start=0;
						markerSetting.paging.end=0;
						getBoardList(menuIndex);
					}
				}
			}
function goSearchEbsList(menuIndex) {
	$("#menuIndex").val(menuIndex);
	$("#searchName").val($("#ebsSearchName").val());
	
	if($("#ebsSearchName").val() == '') {
		alert('검색어를 입력하세요.');
		return;
	}
	var url = "/board/ebsBoardList";	
	
	$("#frm").attr("action", url);
	$("#frm").submit();

}

function hitEnterKey(e){
	  if(e.keyCode == 13){
		  goSearchEbsList(4);			  
		  return false;
	  }
 } 
 
$(function() {
//  	init();
  	DisplayMenu(firstIndex);
  	
  //getBoardList(4);
  	});
function getMsg() {
	alert('준비중 입니다.');
	return;
}
</script>
</body>
</html>	